import { NextResponse } from 'next/server';
import { importRawCsvsFromDir } from '@/lib/raw-csv-importer';

export async function POST(request: Request) {
  try {
    const { directory } = await request.json();

    if (!directory || typeof directory !== 'string') {
      return NextResponse.json({ message: '错误：必须提供目录参数' }, { status: 400 });
    }

    const result = await importRawCsvsFromDir(directory);
    return NextResponse.json(result);

  } catch (error: any) {
    console.error('[API/import-raw-csv] Error:', error);
    return NextResponse.json({ message: `导入失败: ${error.message}` }, { status: 500 });
  }
} 